<form class="layui-form" action="">

    <div class="layui-form">
        <table class="layui-table">
            <colgroup>
                <col width="100">
                <col width="120">
                <col width="150">
                <col width="150">
                <col width="150">
                <col width="80">
                <col width="200">
                <col>
            </colgroup>
            <thead>
            <tr>

                <th>客户姓名</th>
                <th>联系方式</th>
                <th>单位名称</th>
                <th>税号</th>
                <th>地址</th>
                <th width="110">付款方式</th>
                <th>备注</th>
            </tr>
            </thead>
            <tbody>

            {for start="1" end="8"}
                <tr>
                    <td>
                        <input type="text" id="user_name_{$i}" name="user_name[]"  autocomplete="off"
                               class="layui-input">
                    </td>
                    <td>
                        <input type="text" id="tel_{$i}" name="tel[]"  autocomplete="off"
                               class="layui-input">
                    </td>
                    <td>
                        <input type="text" id="unit_name" data-index="{$i}" name="unit_name[]"  autocomplete="off"
                               class="layui-input">
                    </td>
                    <td>
                        <input type="text" id="duty_num" data-index="{$i}" name="duty_num[]"  autocomplete="off"
                               class="layui-input">
                    </td>
                    <td>
                        <input type="text" id="address_{$i}" name="address[]"  autocomplete="off"
                               class="layui-input">
                    </td>
                    <!--<td></td>-->

                    <td>
                        <div class="">
                            <div class="layui-inline">
                                <div class="layui-input-inline">
                                    <select name="pay_period[]">
                                        <option selected value="1">货到付款</option>
                                        <option value="2">月付</option>
                                        <option value="3">季度付</option>
                                        <option value="4">半年付</option>
                                        <option value="5">其他</option>
                                    </select>
                                </div>
                            </div>
                        </div>
                    </td>
                    <td>
                        <input type="text" name="comment[]"  autocomplete="off" class="layui-input">
                    </td>
                </tr>
            {/for}
            </tbody>
        </table>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="text-align: center">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="addData">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'laydate'], function () {
        var form = layui.form
            , laydate = layui.laydate
            , layer = layui.layer;
        //监听提交
        form.on('submit(addData)', function (data) {
            $.ajax({
                url: '{:url("/printer/Customer/add")}',
                type: 'post',
                dataType: 'json',
                data: data.field,
                beforeSend: function () {
                    layer.load(2);
                },
                complete: function () {
                    layer.closeAll('loading');
                },
                success: function (res) {
                    if (res.code == 1) {
                        layer.msg('添加成功', {icon: 1});
                        return false;
                    }
                    layer.alert(res.msg, {icon: 2});
                    return false;
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    layer.alert('网络失败，请联系管理员', {icon: 2});
                }
            });
            return false;
        });
    });
</script>